//CSE 430 - Operating Systems
//Partha Dasgupta
//Spring '12
//Project 4

//Alan Tu
//Kelly Jesionowski

#ifndef _TCB_H
#define _TCB_H

#include <ucontext.h>
#include <string.h>

typedef struct TCB{
    ucontext_t context;
    struct TCB *next;
    struct TCB *prev;
}TCB_t;

void init_TCB(TCB_t *tcb, void *function, void *stackP, int stack_size)
{
    memset(tcb, '\0', sizeof(TCB_t));       				// clears out TCB memory region with 0s
    getcontext(&tcb->context);              				// have to get parent context, else snow forms on hell
    tcb->context.uc_stack.ss_sp = stackP;					// ss_sp points to base of stack
    tcb->context.uc_stack.ss_size = (size_t)stack_size;     // set size of stack pointed to by ss_sp
    makecontext(&tcb->context, function, 0);				// make thread available to be run with swapcontext
}

#endif //_TCB_H
